#!/bin/bash
rootPath=`pwd`
read -p "请输入新包名:" packageName
echo "新的包名是:"$packageName
oldPackageName="com.yadong.template"
echo "旧包名是:"$oldPackageName
echo "开始执行替换， 将java文件中的"$oldPackageName"替换为:"$packageName
find -name "*.java" |xargs sed -i "s/$oldPackageName/$packageName/g"
echo "java文件替换完成开始替换包名"
find -name "*.gradle"|xargs sed -i "s/$oldPackageName/$packageName/g"
echo "gradle文件替换完成"
find -name "*.xml"|xargs sed -i "s/$oldPackageName/$packageName/g"
echo "替换资源文件和AndroidManifest.xml完成"
cd $rootPath/app/src/main/java 
newPackagePath=`echo $packageName | sed "s/\./\//g"`
echo "新的路径名称为:"$newPackagePath
oldPackagePath=`echo $oldPackageName | sed "s/\./\//g"`
echo "旧的路径名称为:"$oldPackagePath
mkdir -p $newPackagePath
echo "开始执行移动从" $oldPackagePath "到" $newPackagePath
mv $oldPackagePath/* $newPackagePath/
echo "移除旧目录"$oldPackagePath
rm -r $oldPackagePath


